/* gtk cairo hello world */

.section .rodata
.LC0:
	.long 0x4dd2f1a9
	.long 0x3fe41062 /* 0.627 */

.LC1:
	.string "WenQuanYi Zen Hei"

.LC2:
	 .long 0x0
	 .long 0x40380000 /* 24.0 */

.LC3:
	 .long 0x0
	 .long 0x40240000 /* 10.0 */

.LC4:
	.long 0x0
	.long 0x40410000 /* 34.0 */

.LC5:
	.string "编程艺术"

.LC6:
	.string "expose-event"

.LC7:
	.string "destroy"


.text
.globl main

on_expose_event:
	pushq %rbp
	movq %rsp,%rbp
	subq $0x1000,%rsp

	movq %rdi,-0x1000(%rbp) /* widget */
	movq %rsi,-0xff8(%rbp) /* event */
	movq %rdx,-0xff0(%rbp) /* data */

	movq $0,-0xfe8(%rbp) /* cr */

	movq -0x1000(%rbp),%rdi /* widget */
	movq 80(%rdi),%rdi /* widget->window*/
	movl $0,%eax
	call gdk_cairo_create 
	movq %rax,-0xfe8(%rbp) /* cr */

	pxor %xmm2,%xmm2
	pxor %xmm1,%xmm1
	movsd .LC0(%rip),%xmm0
	movq -0xfe8(%rbp),%rdi /* cr */
	movl $0,%eax 
	call cairo_set_source_rgb

	movl $0,%ecx
	movl $0,%edx 
	leaq .LC1(%rip),%rsi
	movq -0xfe8(%rbp),%rdi /* cr */
	movl $0,%eax 
	call cairo_select_font_face 

	movsd .LC2(%rip),%xmm0 /* 24.0 */
	movq -0xfe8(%rbp),%rdi /* cr */
	movl $0,%eax 
	call cairo_set_font_size

	movsd .LC4(%rip),%xmm1 /* 34.0 */
	movsd .LC3(%rip),%xmm0  /* 10.0 */
	movq -0xfe8(%rbp),%rdi /* cr */
	movl $0,%eax 
	call cairo_move_to

	leaq .LC5(%rip),%rsi 
	movq -0xfe8(%rbp),%rdi /* cr */
	movl $0,%eax
	call cairo_show_text

	movq -0xfe8(%rbp),%rdi /* cr */
	movl $0,%eax
	call cairo_destroy

	movl $0,%eax
	leave
	ret


main:
	pushq %rbp
	movq %rsp,%rbp
	subq $0x1000,%rsp

	movl %edi,-0x1000(%rbp) /* argc */
	movq %rsi,-0xff8(%rbp)  /* argv */

	movq $0,-0xff0(%rbp) /* window */

	leaq -0xff8(%rbp),%rsi /* argv */
	leaq -0x1000(%rbp),%rdi /* argc */
	movl $0,%eax
	call gtk_init

	movl $0,%edi
	movl $0,%eax 
	call gtk_window_new 
	movq %rax,-0xff0(%rbp) /* window */

	movl $0,%r9d
	movl $0,%r8d 
	movl $0,%ecx 
	leaq on_expose_event(%rip),%rdx 
	leaq .LC6(%rip),%rsi
	movq -0xff0(%rbp),%rdi /* window */
	movl $0,%eax
	call g_signal_connect_data

	movl $0,%r9d
	movl $0,%r8d 
	movl $0,%ecx
	movq gtk_main_quit@GOTPCREL(%rip),%rdx 
	leaq .LC7(%rip),%rsi
	movq -0xff0(%rbp),%rdi /* window */
	movl $0,%eax
	call g_signal_connect_data

	movl $0,%eax 
	call gtk_window_get_type 
	movq %rax,%rsi 
	movq -0xff0(%rbp),%rdi /* window */
	movl $0,%eax
	call g_type_check_instance_cast
	movl $1,%esi
	movq %rax,%rdi
	movl $0,%eax
	call gtk_window_set_position

	movl $0,%eax 
	call gtk_window_get_type 
	movq %rax,%rsi 
	movq -0xff0(%rbp),%rdi /* window */
	movl $0,%eax
	call g_type_check_instance_cast
	
	movl $48,%edx
	movl $320,%esi 
	movq %rax,%rdi
	movl $0,%eax 
	call gtk_window_set_default_size 

	movl $1,%esi
	movq -0xff0(%rbp),%rdi /* window */
	movl $0,%eax
	call gtk_widget_set_app_paintable

	movq -0xff0(%rbp),%rdi /* window */
	movl $0,%eax
	call gtk_widget_show_all

	movl $0,%eax
	call gtk_main

	movl $0,%eax
	leave
	ret
